package com.zili.transformation;

import com.zili.source.Event;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author : ranzlupup
 * @since : 2023/3/7 19:00
 */
public class AggregationKeyBy {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(2);
        DataStreamSource<Event> stream = env.fromElements(
                new Event("Mary", "./home", 1000L),
                new Event("Bob1", "./cart1", 2000L),
                new Event("Bob2", "./cart2", 3000L),
                new Event("Bob1", "./cart3", 4000L),
                new Event("Bob1", "./cart4", 5000L),
                new Event("Bob2", "./cart5", 6000L)
        );
        stream.keyBy(data -> data.user).print();
        env.execute();
    }
}
